let { personCheck, personList } = require("./mock");
const bodyParser = require('body-parser')
const Mock = require('mockjs')
module.exports = (app) => {
  app.use(bodyParser.json())
  app.get("/api/person/check", (req, res) => {
    const { value = "" } = req.query;
    const result = personCheck.filter((v) => v.name.includes(value));
    res.send({
      code: 200,
      data: result,
    });
  });

  app.get("/api/person/check/delete", (req, res) => {
    const { id } = req.query;
    personCheck = personCheck.filter((v) => {
      return v.id !== id;
    });
    res.send({
      code: 200,
			message: '删除成功'
    });
  });
	

  app.get("/api/person/check/:id", (req, res) => {
    const { id } = req.params;
    personCheck = personCheck.filter((v) => {
      if (v.id === id) {
        personList.unshift({ ...v });
      }
      return v.id !== id;
    });
    res.send({
      code: 200,
      message: "审核成功",
    });
  });

  app.get("/api/person/list", (req, res) => {
    res.send({
      code: 200,
      data: personList,
    });
  });

  app.post('/api/person/add', (req, res) => {
    req.body.id = Math.random().toString().slice(2)
    personCheck.unshift(req.body)
    res.send({
      code: 200
    })
  })

  app.post('/api/detail', (req, res) => {
    const { id } = req.body;
    const result = personList.find(v => v.id === id)
    res.send({
      code: 200,
      data: {
        data: result,
        prices: Mock.mock({
          "list|12": ["@integer(10000, 20000)"]
        }).list
      }
    })
  })
};
